﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Controls
{
    public partial class Paging : System.Web.UI.UserControl
    {
        public int numofpage;
        public int currentPage;
        public string catID;
        public int type;
        public int groupID;
        public string site;
        public string var;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string[] listurl = Request.Url.AbsoluteUri.Split('/');
                string url = listurl[listurl.Length - 1];
                if (url == "danhsachsanpham.htm")
                 {
                     site = "danhsachsanpham.htm";
                     if (Request.QueryString["catID"] != null)
                         groupID = Convert.ToInt32(Request.QueryString["catID"].ToString());
                     else
                         Response.Redirect("Error.aspx");
                     var = "catID";
                     int n = ListProduct.AllCat;
                     int size = ListProduct.sizePage;
                     numofpage = (n%size == 0 ? (n/size) : (n/size) + 1);
                     currentPage = ListProduct.currentPage;
                     catID = ListProduct.catID.ToString();


                     rpt_Paging.DataSource =
                         rpt_Paging.DataSource =
                         BOL.ProductManager.Instance.GetTablePagingIndex(n, ListProduct.sizePage,
                                                                         ListProduct.currentPage);
                     rpt_Paging.DataBind();

                 }
                if (url == "boxsanpham.htm")
                 {

                     site = "boxsanpham.htm";
                     if (Request.QueryString["type"] != null)
                         catID = (Request.QueryString["type"].ToString());
                     else
                         Response.Redirect("Error.aspx");
                     var = "type";

                     int n = ListBoxProduct.AllCat;
                     int size = ListBoxProduct.sizePage;
                     numofpage = (n % size == 0 ? (n / size) : (n / size) + 1);
                     currentPage = ListBoxProduct.currentPage;
                    

                     rpt_Paging.DataSource =
                         rpt_Paging.DataSource =
                         BOL.ProductManager.Instance.GetTablePagingIndex(n, ListBoxProduct.sizePage,
                                                                         ListBoxProduct.currentPage);
                     rpt_Paging.DataBind();

                 }
                if (url == "timkiem.htm")
                {

                    site = "timkiem.htm";
                    if (Request.QueryString["content"] != null)
                        catID = (Request.QueryString["content"].ToString());
                    else
                        Response.Redirect("Error.aspx");
                    var = "content";

                    int n = SaleOnlineSystem.ProductSearch.AllCat;
                    int size = SaleOnlineSystem.ProductSearch.sizePage;
                    numofpage = (n % size == 0 ? (n / size) : (n / size) + 1);
                    currentPage = SaleOnlineSystem.ProductSearch.currentPage;


                    rpt_Paging.DataSource =
                        rpt_Paging.DataSource =
                        BOL.ProductManager.Instance.GetTablePagingIndex(n, SaleOnlineSystem.ProductSearch.sizePage,
                                                                        SaleOnlineSystem.ProductSearch.currentPage);
                    rpt_Paging.DataBind();

                }
                if (url == "nhasanxuat.htm")
                {

                    site = "nhasanxuat.htm";
                    if (Request.QueryString["vendorID"] != null)
                        catID = (Request.QueryString["vendorID"].ToString());
                    else
                        Response.Redirect("Error.aspx");
                    var = "vendor";

                    int n = SaleOnlineSystem.VendorSearch.AllCat;
                    int size = SaleOnlineSystem.VendorSearch.sizePage;
                    numofpage = (n % size == 0 ? (n / size) : (n / size) + 1);
                    currentPage = SaleOnlineSystem.VendorSearch.currentPage;


                    rpt_Paging.DataSource =
                        rpt_Paging.DataSource =
                        BOL.ProductManager.Instance.GetTablePagingIndex(n, SaleOnlineSystem.VendorSearch.sizePage,
                                                                        SaleOnlineSystem.VendorSearch.currentPage);
                    rpt_Paging.DataBind();

                }
            }

        }
    }
}